home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 115_01.zip / CONFIG3.C < prev    next >
Text File  |  1993-06-01  |  2KB  |  146 lines

  1. /* Screen editor configurator:  general utilities
  2.  *
  3.  * Source:  config3.c
  4.  * Version: Jan. 10, 1981.
  5.  */
  6.  
  7. /* convert upper case to lower case */
  8.  
  9. tolower(c) char c;
  10. {
  11.     if ((c>='A')*(c<='Z')) {
  12.         return(c+32);
  13.     }
  14.     else {
  15.         return(c);
  16.     }
  17. }
  18.  
  19. /* return: is first token in args a number ? */
  20. /* return value of number in *val            */
  21.  
  22. number(args,val) char *args; int *val;
  23. {
  24. char c;
  25.     c=*args++;
  26.     if ((c<'0')+(c>'9')) {
  27.         return(NO);
  28.     }
  29.     *val=c-'0';
  30.     while (c=*args++) {
  31.         if ((c<'0')+(c>'9')) {
  32.             break;
  33.         }
  34.         *val=(*val*10)+c-'0';
  35.     }
  36.     return(YES);
  37. }
  38.  
  39. /* convert character buffer to numeric */
  40.  
  41. ctoi(buf,index) char *buf; int index;
  42. {
  43. int k;
  44.     while ( (buf[index]==' ') +
  45.         (buf[index]==TAB) ) {
  46.         index++;
  47.     }
  48.     k=0;
  49.     while ((buf[index]>='0')*(buf[index]<='9')) {
  50.         k=(k*10)+buf[index]-'0';
  51.         index++;
  52.     }
  53.     return(k);
  54. }
  55.  
  56.  
  57. /* return maximum of m,n */
  58.  
  59. max(m,n) int m,n;
  60. {
  61.     if (m>=n) {
  62.         return(m);
  63.     }
  64.     else {
  65.         return(n);
  66.     }
  67. }
  68.  
  69. /* return minimum of m,n */
  70.  
  71. min(m,n) int m,n;
  72. {
  73.     if (m<=n) {
  74.         return(m);
  75.     }
  76.     else {
  77.         return(n);
  78.     }
  79. }
  80.  
  81. /* put decimal integer n in field width >= w */
  82.  
  83. putdec(n,w) int n,w;
  84. {
  85. char chars[10];
  86. int i,nd;
  87.     nd=itoc(n,chars,10);
  88.     i=nd;
  89.     while (i++<w) {
  90.         putchar(' ');
  91.     }
  92.     i=0;
  93.     while (i<nd) {
  94.         putchar(chars[i++]);
  95.     }
  96. }
  97.  
  98. /* convert integer n to character string in str */
  99.  
  100. itoc(n,str,size) int n; char *str; int size;
  101. {
  102. int absval;
  103. int len;
  104. int i,j,k;
  105.     absval=abs(n);
  106.     /* generate digits */
  107.     str[0]=0;
  108.     i=1;
  109.     while (i<size) {
  110.         str[i++]=(absval%10)+'0';
  111.         absval=absval/10;
  112.         if (absval==0) {
  113.             break;
  114.         }
  115.     }
  116.     /* generate sign */
  117.     if ((i<size)&(n<0)) {
  118.         str[i++]='-';
  119.     }
  120.     len=i-1;
  121.     /* reverse sign, digits */
  122.     i--;
  123.     j=0;
  124.     while (j<i) {
  125.         k=str[i];
  126.         str[i]=str[j];
  127.         str[j]=k;
  128.         i--;
  129.         j++;
  130.     }
  131.     return(len);
  132. }
  133.  
  134. /* return absolute value of n */
  135.  
  136. abs(n) int n;
  137. {
  138.     if (n<0) {
  139.         return(-n);
  140.     }
  141.     else {
  142.         return(n);
  143.     }
  144. }
  145.  
  146.